package com.longge;

import java.util.List;
import java.util.stream.Collectors;

public class CountPairs {

    public int countPairs(List<Integer> nums, int target) {
        int ans = 0;
        nums = nums.stream().sorted().collect(Collectors.toList());
        for (int i = 0; i < nums.size() - 1; i++) {
            for (int j = i + 1; j < nums.size(); j++) {
                int sum = nums.get(i) + nums.get(j);
                if (sum >= target) {
                    break;
                }
                ans++;
            }
        }
        return ans;
    }
}
